<template>
	<div id="app">
		<router-view></router-view>
	</div>

</template>

<script>
	export default {
		name: "App",
		watch: {
			$route(to, from) {

				console.log("to")
				console.log(to)

				if (to.path != '/login') {
					let obj = {
						name: to.name,
						title: to.meta.title
					}

					this.$store.commit("addTab", obj)
				}

			}
		},
		//关闭时间，清除token,通过时间差判断是关闭还是刷新
		mounted() {
    let beginTime = 0; //开始时间
    let differTime = 0; //时间差
    window.onunload = function () {
      differTime = new Date().getTime() - beginTime;
			debugger
      if (differTime <=1) {
        console.log("这是关闭");
        localStorage.setItem("token", "");
        //退出登录跳到首页
        this.$router.push({ path: "/" });
      } else {
        console.log("这是刷新");
      }
    };
 
    window.onbeforeunload = function () {
      beginTime = new Date().getTime();
    };
  },
	}

</script>

<style>
	html, body, #app {
		font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif;
		height: 100%;
		padding: 0;
		margin: 0;
		font-size: 28px;
		background: url("./image/nutrition.jpeg") no-repeat center;
		background-size: 100%;
	}

	h1,h2 {
		font-size: 18px;
		font-weight: 700;
	}
	.el-form {
		margin-top: 10px;
	}
	.cell {
		text-align: center;
	}


</style>
